package com.donghuayuan.kotlincar

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.donghuayuan.kotlincar.bean.ModelBean
import com.donghuayuan.kotlincar.databinding.ActivityLiveDateAndModeBinding
import com.donghuayuan.kotlincar.net.CarApi
import com.donghuayuan.kotlincar.net.RetrofitUtils
import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response


class LiveDateAndModeActivity : AppCompatActivity() {
    private lateinit var binding:ActivityLiveDateAndModeBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityLiveDateAndModeBinding.inflate(layoutInflater)
        setContentView(binding.root)

    }

    suspend fun doSomething(){
        val api = RetrofitUtils.getApi(CarApi.base_url, CarApi::class.java)
        val call = api.getModelList("10", "2025",CarApi.key)
        call?.enqueue(object :Callback<ModelBean>{
            override fun onResponse(call: Call<ModelBean>, response: Response<ModelBean>) {
                val bean = response.body()
                val gson= Gson()
                println("请求成功"+gson.toJson(bean))
            }

            override fun onFailure(call: Call<ModelBean>, t: Throwable) {

            }

        })
    }
}